package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.pojo.seckill.SeckillGoods;
import com.qingcheng.service.seckill.SeckillGoodsService;
import com.qingcheng.utils.DateUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/seckill/goods")
public class SeckillGoodsController {

    @Reference
    private SeckillGoodsService seckillGoodsService;

    /**
     * 获取时间菜单
     * @return
     */
    @GetMapping("/menus")
    public List<Date> dateMenus() {
        List<Date> dateMenus = DateUtil.getDateMenus();
        return dateMenus;
    }

    /**
     * 查询商品列表
     * @param time
     * @return
     */
    @GetMapping("/list")
    public List<SeckillGoods> searchList(String time) {
        List<SeckillGoods> seckillGoods = seckillGoodsService.searchList(DateUtil.formatStr(time));
        return seckillGoods;
    }

    /**
     * 根据id查询商品详情
     * @param time
     * @param id
     * @return
     */
    @GetMapping("/one")
    public SeckillGoods one(String time,Long id) {
        return seckillGoodsService.one(time,id);
    }
}
